const app = getApp()
console.log(app.globalData.user)
Page({
  data: {
    checked1: false,
    checked2: false,
    checked3: false,
    user:'',
    id:'',
    senduser:''
  },

  onChange1({ detail }) {
    // 需要手动对 checked 状态进行更新
    this.setData({ checked1: detail });
  },
  onChange2({ detail }) {
    // 需要手动对 checked 状态进行更新
    this.setData({ checked2: detail });
  },
  onChange3({ detail }) {
    // 需要手动对 checked 状态进行更新
    this.setData({ checked3: detail });
  },
  gotoHome(){
    wx.navigateTo({
      url: `/pages/other/other?findid=${this.data.id}`,
    })
  },
  gotofindchat(){
    wx.navigateTo({
      url: `/pages/findchat/findchat?id=${this.data.id}`,
    })
  },
  report(){
    wx.navigateTo({
      url: '/pages/report/report',
    })
  },
  clear(){
    wx.request({
      url: `http://localhost:3000/message/clearchat?id=${this.data.senduser.id}&receiveid=${this.data.id}`,
      method:"GET",
      success:res=>{
        console.log(res.data)
        wx.showToast({
          title: "清空成功",
        })
      },
      fail:err=>{
        console.error(err)
      }
    })
  },
  clearchat(){
    let that = this
    wx.showModal({
      content: '确定删除和该用户的聊天记录，一旦删除无法恢复？',
        success: function (sm) {
          if (sm.confirm) {
            that.clear()
          } else if (sm.cancel) {
            wx.showToast({
              title: "取消删除",
            })
          }
        }
    }) 
  },
  /**
   * 生命周期函数--监听页面加载
  */
 onLoad(options){
   console.log(options.id)
  this.setData({
    id:options.id,
    senduser:app.globalData.user,
  })
  console.log(this.data.id)
  wx.request({
    url: `http://localhost:3000/message/getreceiveid?receiveid=${this.data.id}`,
    method:'GET',
    success:res=>{
      this.setData({
        user:res.data.user
      })
      console.log(this.data.user,this.data.senduser)
    },
    fail:err=>{
      console.error(err)
    }
  })
},
});
